﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BartonExtension;

namespace SqliteWrapper
{
    public class QueryAttribute
    {
        public string AttrFieldName { get; set; }
        public string AttrTextName { get; set; }
        public bool isScript { get; set; }

        public QueryAttribute(string attr)
        {
            if (attr.IndexOf("[script]") != -1)
            {
                isScript = true;
                attr = attr.Replace("[script]", "");
            }
            string[] attribute = attr.Split(new string[]{"as"},StringSplitOptions.None);
            AttrFieldName = AttrTextName = attribute[0].Trim();
            if (attribute.Length > 1)
            {
                if (attribute[1].isNullOrEmpty())
                    AttrTextName = attribute[0].Trim();
                else
                    AttrTextName = attribute[1].Trim();
            }
        }

        public static string Script(string script)
        {
            return "[script]{0}".FormatWith(script);
        }
    }
}
